﻿using JZ_UDI.DataAccess;
using JZ_UDI.DataAccess.DataEntity;
using Sunny.UI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.Entity.Infrastructure;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using NLog;
using LogLevel = NLog.LogLevel;
using CommonHelper;
using System.Data.SqlClient;

namespace JZ_UDI.View.Settings
{
    public partial class frmAddUser : UIForm
    {

        public delegate void AddFinishFormClose(object sender,string username);
        public event AddFinishFormClose addFormClose;

        public frmAddUser()
        {
            InitializeComponent();
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            //using (var context = new EFDbContext())
            //{
            //    List<User> lists = context.Users.ToList();

            //    User _user = lists.Find(o => o.UserName.Equals(txtUid.Text.Trim()));
            //    if (_user != null)
            //    {
            //        MessageBox.Show("帐号已经存在","提示",MessageBoxButtons.OK,MessageBoxIcon.Warning);
            //        return;
            //    }


            //    string sql = "insert into User(UserName,Password) values (@uid,@pwd)";
            //    var parameters2 = new SqlParameter[]
            //    {
            //                new SqlParameter("@uid", ),
            //                new SqlParameter("@pid",)
            //    };
            //    context.Database.ExecuteSqlCommand(sql, parameters2);

            //    _user = new User();
            //    _user.UserName= txtUid.Text.Trim();
            //    _user.Password=MD5Helper.MD5Encrypt32(txtPwd.Text.Trim());
            //    lists.Add(_user);
            //    int count=context.SaveChanges();
            //    if (count > 0)
            //    {
            //        this.Close();
            //        addFormClose?.Invoke(this, _user.UserName);
            //    }
            //}
            this.Close();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
        }
    }
}
